<template>
    <div>
<h2>房号添加</h2>
<table class="table table-bordered">
    <tr >
        <td align="right">房型名称</td>
        <td><input type="text" v-model="state.hName"></td>
    </tr>
    <tr >
        <td align="right">房号</td>
        <td><input type="text" v-model="state.hNum"></td>
    </tr>
    <tr >
        <td align="right">排序</td>
        <td><input type="text" v-model="state.paiXu"></td>
    </tr>
    <tr >
        <td align="right">备注</td>
        <td><input type="text" v-model="state.remate"></td>
    </tr>
    <tr >
        <td align="right">状态</td>
        <td><input type="text" v-model="state.states"></td>
    </tr>
    <tr >
        <td></td>
        <td><input type="button" value="登录" @click="add"></td>
    </tr>
</table>
    </div>
</template>

<script setup lang="ts">
import { reactive,toRefs } from 'vue';
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
const router=useRouter()
let data=reactive({
    state:{
        hName: "",
  hNum: "",
  paiXu: "",
  remate: "",
  states: "",
    }
})
let {state}=toRefs(data)
const add=()=>{
    if(state.value.hName==""){
        alert("房型名称不能为空")
        return;
    }
    if(state.value.hNum==""){
        alert("房号不能为空")
        return;
    }
    if(state.value.paiXu==""){
        alert("排序不能为空")
        return;
    }
    if(state.value.remate==""){
        alert("备注不能为空")
        return;
    }
    if(state.value.states==""){
        alert("状态不能为空")
        return;
    }
    let obj={
        id: 0,
        hName:state.value.hName,
        hNum:state.value.hNum,
        paiXu:state.value.paiXu,
        remate:state.value.remate,
        states:state.value.states,
        isDelete: false
    }
    axios({
        url:'/api/HouseNum/HouseNumAdd',
        method:'post',
        data:obj
    })
    .then(res=>{
        console.log(res)
        if(res.data==1){
alert("登录成功")
router.push('/housenumlist')
        }
        else{
            alert("登录失败")
            return;
        }
    })
    .catch(err=>{
        console.log(err)
    })
}
</script>

<style scoped>

</style>